package com.biz.ssm.base;


import java.io.Serializable;
import java.util.List;

public abstract class BaseServiceImpl<T,ID extends Serializable,D extends BaseMapper> implements BaseService<T,ID> {

	public abstract D getMapper() ;

    @Override
	public T selectById(ID id) {
    	return (T) getMapper().selectById(id);
    }

    @Override
    public int deleteById(ID id){
    	return getMapper().deleteById(id);
    }

    @Override
	public Long insert(T record){
    	return getMapper().insert(record);
    }

    @Override
	public int update(T record){
    	return getMapper().update(record);
    }

    @Override
	public Page<T> findPage(Pageable pageable){
		List<T> list = getMapper().findList(pageable);
		Integer count = getMapper().countForList(pageable);
		Page<T> page = new Page<T>(list, count, pageable);
		return page;
    }

    @Override
	public Integer countPage(Pageable pageable){
		Integer count = getMapper().countForList(pageable);
		return count;
    }

    @Override
    public void removeBeans(ID[] ids){
    	for(int i=0;i<ids.length;i++){
            ID tempId = ids[i];
			if(tempId != null){
				this.getMapper().deleteById(tempId);
			}
		}
    }

    @Override
	public List<T> findAll(){
		return getMapper().findAll();
    }

    @Override
    public Integer count() {
    	return getMapper().count();
    }

    @Override
	public T selectByUserId(ID userId) {
    	return (T) getMapper().selectByUserId(userId);
    }

	@Override
	public int insertList(List<T> list) {
		return getMapper().insertList(list);
	}
}
